﻿using System;
using Silver3D.Math;

namespace Silver3D.Graphics
{
    /// <summary>
    /// Represents a quaternion-based rotation transform.
    /// </summary>
    public class QuaternionTransform : MatrixTransform
    {
        private Quat quaternion = Quat.Identity;

        /// <summary>
        /// Gets or sets the quaternion.
        /// Default value is Quat.Identity.
        /// </summary>
        public Quat Quaternion
        {
            get { return quaternion; }
            set
            {
                quaternion = value;
                IsDirty = true;
            }
        }

        public QuaternionTransform(Scene scene, string id)
            : base(scene, id)
        {
        }

        public QuaternionTransform(Scene scene, string id, Node parent)
            : base(scene, id, parent)
        {
        }

        public QuaternionTransform(Scene scene, string id, Node parent, Quat quaternion)
            : base(scene, id, parent)
        {
            Quaternion = quaternion;
        }

        /// <summary>
        /// Updates the CachedMatrix member to the quaternion's matrix representation.
        /// </summary>
        protected override void UpdateMatrix()
        {
            CachedMatrix = quaternion.ToMatrix();
        }
    }
}
